Skip to content

Conversation

@ChrisRackauckas
Copy link
Member

Summary

Problem

When using Optimization.LBFGS() with constraints but without specifying maxiters, the solver would throw an error because maxiters was nothing, causing an error when creating the range 1:maxiters in the constrained optimization path at line 178 of lbfgsb.jl.

Solution

Added a default value of 1000 iterations for constrained problems when maxiters is not specified. This matches the implicit behavior of unconstrained problems and is consistent with common practice in the codebase.

Test plan

The test verifies that:

  1. The solver doesn't throw an error when maxiters is not specified
  2. The optimization either succeeds or returns MaxIters (but doesn't crash)
  3. If it converges, the constraint is satisfied

🤖 Generated with Claude Code

…maxiters

This commit fixes issue #958 where using Optimization.LBFGS() with
constraints but without specifying maxiters would throw:
'MethodError: no method matching (::Colon)(::Int64, ::Nothing)'

The issue occurred because maxiters was nothing when not specified,
causing an error when creating the range 1:maxiters in the constrained
optimization path.

The fix adds a default value of 1000 iterations for constrained problems
when maxiters is not specified, matching the behavior of unconstrained
problems.

Also adds a test case to prevent regression.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas
Copy link
Member Author

No this is wrong.

@ChrisRackauckas ChrisRackauckas deleted the fix-lbfgs-constrained-maxiters branch July 28, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no method matching (::Colon)(::Int64, ::Nothing) when trying to solve a constrained problem with Optimization.LBFGS

3 participants